<?php

@include_once('./database.php');

$uname = $_POST['username'];

$obj = [];



$sql = "select * from cart , goods_list where goods_list.goods_id = cart.goods_id and user_name = '$uname'";
// 默认只会转第一条数据
$res = mysqli_query($connect, $sql);

$list = [];

while($data = mysqli_fetch_array($res)) {
    $temp = [] ;
    $temp['id'] = $data['goods_id'] ;
    $temp['name'] = $data['goods_name'] ;
    $temp['title'] = $data['goods_title'] ;
    $temp['des'] = $data['goods_des'] ;
    $temp['img'] = $data['goods_img'] ;
    $temp['price'] = $data['goods_price'] ;
    $temp['num'] = $data['cart_num'] ;
    array_push($list , $temp) ;
}

if($list) {
    $obj['status'] = true ;
    $obj['msg'] = '数据请求成功';
    $obj['data'] = $list ;
} else {
    $obj['status'] = false ;
    $obj['msg'] = '购物车为空';
    $obj['data'] = $list ;
}

echo(json_encode($obj , JSON_UNESCAPED_UNICODE));